package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.MesMessage;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserFriend;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserFriendService;
import com.ruoyi.system.service.impl.SysUserFriendServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import net.sf.jsqlparser.schema.Sequence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.Part;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/system/userFriend")
public class SysUserFriendController {
    @Autowired
    private ISysUserFriendService userFriendService;

    @GetMapping("/list")
    private AjaxResult selectUserFriendList(){
        SysUser user = SecurityUtils.getLoginUser().getUser();
        List<SysUserFriend> sysUserFriends = userFriendService.selectUserFriendList(user.getUserId().intValue());
        return AjaxResult.success(sysUserFriends);
    }
    @GetMapping("/selectHistory")
    public AjaxResult selectMessageById(@RequestParam("userId")int userId, @RequestParam("friendId")int friendId){
        startPage();
        List<MesMessage> mesMessages = userFriendService.selectMessageById(userId, friendId);
        return AjaxResult.success(mesMessages);
    }
    @PostMapping("/insertHistory")
    public AjaxResult insertHistory(@RequestBody MesMessage message){
        int i = userFriendService.insertHistory(message);
        return AjaxResult.success(i);
    }
}
